package splug.cjk;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayList;
import splug.cjk.packet.BBSPacket;
import splug.cjk.packet.FriendPacket;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class ReportTab2 extends ListActivity{
	
	private String id;
	private ArrayAdapter<String> adapter;
	private ArrayList<String> content = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.report_tab2);
		setTitle("신고 처리 현황");

		//나의 아이디 받아오기
		Bundle b = this.getIntent().getExtras();
		id = b.getString("ID");

		//컴포넌트들의 ID를 받아온다
		Button btn_back = (Button) findViewById(R.id.btn_report_tab2_back);
		ListView lv = getListView();

		//뒤로가기 버튼 이벤트 추가
		btn_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		//신고 처리 현황 리스트 받아오기(24번 요청)
		try {
			Socket socket = new Socket(LetsGoActivity.server_ip, 2007);
			
			InputStream is = socket.getInputStream();
			OutputStream os = socket.getOutputStream();
			
			OutputStreamWriter osw = new OutputStreamWriter(os);
			InputStreamReader isr = new InputStreamReader(is);
			
			osw.write(24);
			osw.flush();
			
			int ack = isr.read();
			
			if(ack == '1'){
				//나의 아이디를 전송해준다
				FriendPacket packet = new FriendPacket(null, id, null);
				ObjectOutputStream output = new ObjectOutputStream(os);
				output.writeObject(packet);
				
				//처리현황을 받아온다
				ObjectInputStream input = new ObjectInputStream(is);
				packet = (FriendPacket) input.readObject();
				
				content = packet.getFriend_list();
				
			}
			else{
				Toast.makeText(ReportTab2.this, "네트워크 연결상대가 좋지 않습니다", Toast.LENGTH_SHORT).show();
				finish();
			}
			
			
		} catch (Exception e) {
			Toast.makeText(ReportTab2.this, "네트워크 연결상대가 좋지 않습니다", Toast.LENGTH_SHORT).show();
			finish();
		} 
		
		adapter = new ArrayAdapter<String>(ReportTab2.this, android.R.layout.simple_list_item_1, content);
		setListAdapter(adapter);
	}

}
